import { createAction, Property } from '@activepieces/pieces-framework';
import { recallAiAuth } from '../common/auth';
import { makeRequest } from '../common/client';
import { HttpMethod } from '@activepieces/pieces-common';

export const createBot = createAction({
  auth: recallAiAuth,
  name: 'createBot',
  displayName: 'create bot',
  description: 'Creates a new bot that will join a meeting',
  props: {
    meeting_url: Property.ShortText({
      displayName: 'Meeting URL',
      description:
        'The URL of the meeting (e.g., https://zoom.us/j/123?pwd=456)',
      required: true,
    }),
    bot_name: Property.ShortText({
      displayName: 'Bot Name',
      description:
        'The name of the bot that will be displayed in the call (max 100 characters). Defaults to "Meeting Notetaker"',
      required: false,
    }),
    // recording_config: Property.Json({
    //   displayName: 'Recording Config',
    //   description:
    //     'Configure the recording generated by the bot including transcript options, layout, and when to start recording',
    //   required: false,
    //   defaultValue: {},
    // }),
    // output_media: Property.Json({
    //   displayName: 'Output Media',
    //   description:
    //     'Settings for the bot output media including video and audio output options',
    //   required: false,
    // }),
    // chat: Property.Json({
    //   displayName: 'Chat',
    //   description:
    //     'Settings for the bot to send chat messages (supported for Zoom, Google Meet, and Microsoft Teams)',
    //   required: false,
    // }),
    // automatic_leave: Property.Json({
    //   displayName: 'Automatic Leave',
    //   description: 'Configure when the bot automatically leaves the meeting',
    //   required: false,
    // }),
    // variant: Property.Json({
    //   displayName: 'Variant',
    //   description:
    //     'Configure bot variants per meeting platforms (e.g., {"zoom": "web_4_core"})',
    //   required: false,
    // }),
    // breakout_room: Property.Json({
    //   displayName: 'Breakout Room',
    //   description:
    //     'Configure how the bot handles breakout rooms (Zoom only). Options: {"mode": "join_main_room"}, {"mode": "join_specific_room", "room_id": ""}, or {"mode": "auto_accept_all_invites"}',
    //   required: false,
    // }),
    // metadata: Property.Json({
    //   displayName: 'Metadata',
    //   description: 'Custom metadata to attach to the bot',
    //   required: false,
    // }),
  },
  async run(context) {
    const {
      meeting_url,
      bot_name,

      // recording_config,
      // output_media,
      // chat,
      // automatic_leave,
      // variant,
      // zoom,
      // google_meet,
      // breakout_room,
      // metadata,
    } = context.propsValue;

    const body: Record<string, unknown> = {
      meeting_url,
    };

    if (bot_name) {
      body['bot_name'] = bot_name;
    }

    // if (recording_config) {
    //   body['recording_config'] = recording_config;
    // }

    // if (output_media) {
    //   body['output_media'] = output_media;
    // }

    // if (chat) {
    //   body['chat'] = chat;
    // }

    // if (automatic_leave) {
    //   body['automatic_leave'] = automatic_leave;
    // }

    // if (variant) {
    //   body['variant'] = variant;
    // }

    // if (zoom) {
    //   body['zoom'] = zoom;
    // }

    // if (google_meet) {
    //   body['google_meet'] = google_meet;
    // }

    // if (breakout_room) {
    //   body['breakout_room'] = breakout_room;
    // }

    // if (metadata) {
    //   body['metadata'] = metadata;
    // }

    const response = await makeRequest(
      context.auth.props.server,
      context.auth.props.api_key,
      HttpMethod.POST,
      '/bot/',
      body
    );

    return response;
  },
});
